#ifndef     __ERROR_H
#define     __ERROR_H

#include <stdint.h>

namespace utils {

namespace ec {

constexpr uint8_t OK = 0x00;
constexpr uint8_t FLASH_WRITE_FAIL = 0x01;
constexpr uint8_t FLASH_ERASE_FAIL = 0x02;
constexpr uint8_t FLASH_CHECK_FAIL = 0x03;
constexpr uint8_t TEMP_FAIL = 0x04; // 温度传感器异常
constexpr uint8_t DOOR_MOTOR_LOCKED = 0x05;
constexpr uint8_t DOOR_MOTOR_TIMEOUT = 0x06;
constexpr uint8_t NOT_RECV_ACK = 0x07;
constexpr uint8_t PARSE_FAIL = 0x08;
constexpr uint8_t INVALID = 0x09;
constexpr uint8_t CONNOT_CMD = 0x0A;
constexpr uint8_t NOZZLE_LOCKED = 0x0B;
constexpr uint8_t NOZZLE_TIMEOUT = 0x0C;
constexpr uint8_t FLOW_FAIL = 0x0D;
constexpr uint8_t DRAW_TIMEOUT = 0x0E;
constexpr uint8_t NOT_BOWL = 0x0F;
constexpr uint8_t RFID_CONN_TIMEOUT = 0x10;

}

struct Error {

public:
    inline Error() : val(ec::OK) {}
    inline Error(uint8_t v) : val(v) {}

    Error(bool) = delete;

    Error& operator=(bool) = delete;

    inline Error& operator=(const Error &other) {
        val = other.val;
        return *this;
    }

    inline Error& operator=(const uint8_t v) {
        val = v;
        return *this;
    }

    inline operator bool() const {
        return val != ec::OK;
    }

    inline bool is_ok() const { return val == ec::OK; }

    inline bool operator==(const Error &other) const {
        return(val == other.val);
    }

    inline bool operator!=(const Error &other) const {
        return (val != other.val);
    }

    inline bool operator!=(uint8_t ec) const {
        return val != ec;
    }
    inline bool operator==(uint8_t ec) const {
        return val == ec;
    }

    uint8_t val;
};


}


#endif
